#include "stdafx.h"
#include "KeyManager.h"

CKeyManager* CKeyManager::ms_Instance = NULL;

void CKeyManager::Update(bool bIsKeyPress, unsigned char keyCode)
{
	switch (keyCode)
	{
	case 'W': case 'w':
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_W : m_iKeyDown&(~KEY_W);
		break;
	case 'A': case 'a':
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_A : m_iKeyDown&(~KEY_A);
		break;
	case 'S': case 's':
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_S : m_iKeyDown&(~KEY_S);
		break;
	case 'D': case 'd':
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_D : m_iKeyDown&(~KEY_D);
		break;
	case 37: // left
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_LEFT : m_iKeyDown&(~KEY_LEFT);
		break;
	case 38: // up
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_UP : m_iKeyDown&(~KEY_UP);
		break;
	case 39: // right
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_RIGHT : m_iKeyDown&(~KEY_RIGHT);
		break;
	case 40: // down
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_DOWN : m_iKeyDown&(~KEY_DOWN);
		break;
	case 'F': case 'f':
		m_iKeyDown = (bIsKeyPress)? m_iKeyDown|KEY_F : m_iKeyDown&(~KEY_F);
		break;
	}
}

bool CKeyManager::WasKeyDown(unsigned int key)
{
	return (m_iKeyDown & key) == key;
}

void CKeyManager::Clear()
{
	m_iKeyDown &= 0x00;
	m_iKeyUp &= 0x00;
}
